var purl = "/wcsi/img/nopicture.png";

$("#locationimg").click(function(ev) {
	setAutoLocation(0);
	GetYourLocation();
	// GetLocationWithHTMLAPI();
});

$("body").on("click","#locationDes",function() {
	setAutoLocation(0);
	GetYourLocation();
	// GetLocationWithHTMLAPI();
});
$("body").on("click","#locationDes2",function() {
	$("#locationDes2").html("正在获取位置......");
	setAutoLocation(0);
	if(_phoneType=="Android"){
		window.jump.reSetLocation();
	}else if(_phoneType=="Ios"){
		window.webkit.messageHandlers.getLocation.postMessage({body: ''});
	}
});

$("body").on("click",".gotomap",function() {
	$("#mapLocationDes").html($(this).parent().next().html());
});
function getPhotoOrientation(img,$img){
    var Orientation;
    EXIF.getData(img, function () {
    	$("#popupView").popup("open");
    	Orientation = EXIF.getTag(this, 'Orientation');
        
        var _imgWidth_act = img.naturalWidth;     //图片宽度
        var _imgHeight_act = img.naturalHeight;   //图片高度
        
        var _imgWidth = img.naturalWidth;     //图片宽度
        var _imgHeight = img.naturalHeight;   //图片高度
        
        if(_imgWidth_act>400){
        	_imgWidth=400;
        	_imgHeight =(400*_imgHeight_act)/_imgWidth_act;
        }
        var canvas= document.createElement('canvas');
        canvas.width=_imgWidth;  
        canvas.height=_imgHeight;
		 var ctx=canvas.getContext('2d');
		 
		 if(Orientation && Orientation != 1){
             switch(Orientation){
                 case 6:     // 旋转90度 
                	 canvas.width = _imgHeight;    
                     canvas.height = _imgWidth; 
                     ctx.rotate(Math.PI / 2);
                     // (0,-imgHeight) 从旋转原理图那里获得的起始点
                     ctx.drawImage(this, 0, -_imgHeight, _imgWidth, _imgHeight);
                     break;
                 case 3:     // 旋转180度
                     ctx.rotate(Math.PI);    
                     ctx.drawImage(this, -_imgWidth, -_imgHeight, _imgWidth, _imgHeight);
                     break;
                 case 8:     // 旋转-90度
                     canvas.width = _imgHeight;    
                     canvas.height = _imgWidth;    
                     ctx.rotate(3 * Math.PI / 2);    
                     ctx.drawImage(this, -_imgWidth, 0, _imgWidth, _imgHeight);
                     break;
             }
         }else{
        	 ctx.drawImage(img,0, 0, _imgWidth,_imgHeight);
         }
		 
		 /*ctx.rotate(Math.PI / 2);
		 ctx.drawImage(img,0, 0, _imgWidth,_imgHeight);*/
		 
		$img.attr('src', canvas.toDataURL('dimg/png'));
		$("#popupView").popup("close");
    });
}
$("#file_upload")
		.change(
				function() {
					var $file = $(this);
					var fileObj = $file[0];
					var windowURL = window.URL || window.webkitURL;
					var dataURL;
					var $img = $("#avatart");

					if (fileObj && fileObj.files && fileObj.files[0]) {
						dataURL = windowURL.createObjectURL(fileObj.files[0]);
						var img =new Image();
						img.src=dataURL;
						
						
						img.onload = function() {
							getPhotoOrientation(img,$img);
							var file = document.getElementById($file.attr("id"));
							file.value = ''; 
						}
					} else {
						dataURL = $file.val();
						var imgObj = document.getElementById("preview");
						// 两个坑:
						// 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
						// 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
						imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
						imgObj.filters
								.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

					}
				});
jQuery('#fileclick').on('click', function() {
	return $("#file_upload").click();
});
jQuery('#detailfileclick').on('click', function() {
	var a = $("#currentId").val();
	return $("#file_" + a).click();
});
var oldlist = [];

jQuery('#deleteBtnT').on('click', function() {

	var a = $("#currentId").val();

	if (oldlist == null) {
		oldlist = [];
	} else {
		for (var i = 0; i < oldlist.length; i++) {
			if (oldlist[i].id == a) {
				$("#" + oldlist[i].id + "_li_ext").remove();
				$("#file_" + oldlist[i].id).remove();
				oldlist.splice(i, 1);
				break;
			}
		}
		$('#eventExts').listview('refresh');
	}
});
jQuery('#saveBtnT')
		.on(
				'click',
				function() {

					var a = $("#currentId").val();
					var imgurl = $("#avatartD").attr("src");

					if (imgurl == "/wcsi/img/upload.png") {
						imgurl = purl;
					}

					var o = {
						"id" : a,
						"registerEventName" : $("#registerEventName").val(),
						"registerEventIdentify" : $("#registerEventIdentify")
								.val(),
						"registerEventMemo" : $("#registerEventMemo").val(),
						"registerEventContent" : $("#registerEventContent")
								.val(),
						"registerEventEvaluateLevel" : $(
								"#registerEventEvaluateLevel").val(),
						"registerEventSeriousLevel" : $(
								"#registerEventSeriousLevel").val(),
						"acceptLimitSpan" : $("#acceptLimitSpan").val(),
						"dealLimitSpan" : $("#dealLimitSpan").val(),
						"registerEventAdress" : $("#locationDes2").html()==''?$("#locationDes").html():$("#locationDes2").html()

					};

					if ($("#" + a + "_ext").attr("id") == undefined) {
						if (oldlist == null) {
							oldlist = [];
						}
						oldlist.push(o);
						var contenthtml = '<li id="'
								+ a
								+ '_li_ext">'
								+ '<a id="'
								+ a
								+ '_ext" href="#eventRegisterPanel" identifyEventTypeId="'
								+ a
								+ '" data-transition="slide" class="eventRegisterclick">'
							    + '<div class="listViewImg">'
								+ '<img width="30%" src="'
								+ imgurl
								+ '" id="'
								+ a
								+ '_avatartD"/>'
								+ ' </div>'
								+ '<div class="listViewContent">'
								+ '<P class="listViewTitle" id="'
								+ a
								+ '_registerEventName_ext">'
								+ o.registerEventName
								+ '</p>'
								+ '<p class="listViewMemo" id="'
								+ a
								+ '_registerEventContent_ext">'
								+ o.registerEventContent
								+ '</p>'
								+ '</div>';
//								+ '<div style="overflow: auto;padding-top:0;margin-left:20px;">'
//								+ '<div class="div-inline"><p id="'
//								+ a
//								+ '_acceptLimitSpan_ext" style="margin:0;">接收时限:'
//								+ o.acceptLimitSpan + '小时</p></div>'
//								+ '<div class="div-inline"><p id="' + a
//								+ '_dealLimitSpan_ext" style="margin:0;">处理时限:'
//								+ o.dealLimitSpan + '小时</p></div></div>'
								+ '</a>' + '</li>';
						$("#eventExts").append(contenthtml);
						$('#eventExts').listview('refresh');
						var t = $("#eventExts li a");
						for (var i = 0; i < t.length; i++) {
							t.removeClass("ui-btn-icon-right");
						}
						
					} else {
						$("#" + a + "_avatartD").attr("src", imgurl);
						$("#" + a + "_registerEventName_ext").html(
								o.registerEventName);
						$("#" + a + "_registerEventContent_ext").html(
								o.registerEventContent);
						$("#" + a + "_acceptLimitSpan_ext").html(
								"接收时限:" + o.acceptLimitSpan + "小时");
						$("#" + a + "_dealLimitSpan_ext").html(
								"处理时限:" + o.dealLimitSpan + "小时");

						for (var i = 0; i < oldlist.length; i++) {
							if (oldlist[i].id == a) {
								oldlist[i] = o;
							}
						}
					}
				});
$("body")
		.on(
				"change",
				".fileClick",
				function() {
					var $file = $(this);
					var fileObj = $file[0];
					var windowURL = window.URL || window.webkitURL;
					var dataURL;
					var $img = $("#avatartD");

					if (fileObj && fileObj.files && fileObj.files[0]) {
						dataURL = windowURL.createObjectURL(fileObj.files[0]);
						
						var img =new Image();
						img.src=dataURL;
						img.onload = function() {
							getPhotoOrientation(img,$img);
							/*var _imgWidth_act = img.naturalWidth;     //图片宽度
					        var _imgHeight_act = img.naturalHeight;   //图片高度
					        
					        var _imgWidth = img.naturalWidth;     //图片宽度
					        var _imgHeight = img.naturalHeight;   //图片高度
					        
					        if(_imgWidth_act>400){
					        	_imgWidth=400;
					        	_imgHeight =(400*_imgHeight_act)/_imgWidth_act;
					        }
					      
							 //var canvas=document.getElementById("picCanvals");
					        var canvas= document.createElement('canvas');
					        canvas.width=_imgWidth;  
			                canvas.height=_imgHeight;
							 var ctx=canvas.getContext('2d');
							 ctx.drawImage(img,0, 0, _imgWidth,_imgHeight);
							$img.attr('src', canvas.toDataURL('dimg/png'));*/
							var file = document.getElementById($file.attr("id"));
							file.value = '';
						}
						
						//$img.attr('src', dataURL);
					} else {
						dataURL = $file.val();
						var imgObj = document.getElementById("preview");
						// 两个坑:
						// 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
						// 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
						imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
						imgObj.filters
								.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

					}
				});

$(document).ready(
	function() {
		$("#goHome").attr("href",$("#goHome").attr("href") + "&&identify="+ $('#identify').val());
		GetEventType(0, "firsteventTypes", "#pageone", "");
		GetYourLocation();
		// GetLocationWithHTMLAPI();
});

// 中间层级点击事件
$("body").on(
		"click",
		".eventTypeclick",
		function() {
			var a = $(this).attr("id");
			var level = $(this).attr("userdefineid");
			GetEventType(a, level + "_middleeventTypes", $(this).attr("href"),
					$("#" + a + "_middleidentify").html());
		});
// 最后一级事件类型点击事件
$("body")
		.on(
				"click",
				".eventRegisterclick",
				function() {
					var a = $(this).attr("identifyEventTypeId");
					$("#currentId").val(a);

					if ($("#" + a + "_avatartD").attr("src") != undefined
							&& $("#" + a + "_avatartD").attr("src") != purl) {
						$("#avatartD").attr("src",
								$("#" + a + "_avatartD").attr("src"));
					} else {
						$("#avatartD").attr("src", '/wcsi/img/upload.png');
					}
					var isOk = false;
					if (oldlist != null) {
						for (var i = 0; i < oldlist.length; i++) {
							if (oldlist[i].id == a) {
								isOk = true;
								$("#registerEventName").val(
										oldlist[i].registerEventName);
								$("#registerEventIdentify").val(
										oldlist[i].registerEventIdentify);
								$("#registerEventMemo").val(
										oldlist[i].registerEventMemo);
								$("#registerEventContent").val(
										oldlist[i].registerEventContent);
								$("#registerEventEvaluateLevel").val(
										oldlist[i].registerEventEvaluateLevel);// 直接是id
								$("#registerEventSeriousLevel").val(
										oldlist[i].registerEventSeriousLevel);// 直接是id
								$("#acceptLimitSpan").val(
										oldlist[i].acceptLimitSpan);
								$("#dealLimitSpan").val(
										oldlist[i].dealLimitSpan);

								break;
							}
						}
					}
					if (!isOk) {
						$("#registerEventName").val(
								$("#" + a + "_eventTypeName").html());
						$("#registerEventMemo").val($("#reportMemo").val());
						$("#registerEventContent").val(
								$("#reportContent").val());
						var acceptLimitSpan = $("#" + a + "_acceptLimitSpan")
								.html();
						$("#acceptLimitSpan").val(
								acceptLimitSpan.substring(5,
										acceptLimitSpan.length - 2));
						var dealLimitSpan = $("#" + a + "_dealLimitSpan")
								.html();
						$("#dealLimitSpan").val(
								dealLimitSpan.substring(5,
										dealLimitSpan.length - 2));

						$
								.ajax({
									url : rootPath
											+ "/ui/eventReport/getRealTimeEventIdentify?eventTypeId="
											+ a + "&longitude="
											+ $("#lng").val() + "&latitude="
											+ $("#lat").val(),
									dataType : 'json',
									type : 'get',
									contentType : "application/json",
									success : function(result) {
										if (result.data.codeForEventIdentify <= 0) {
											message("实时获取事件编码失败!");
										} else {
											$("#registerEventIdentify").val(
													result.data.eventIdentify);
										}
									}
								});
						/* $("#registerEventIdentify").val($("#"+a+"_middleidentify").html()); */
					}
				});
// 获取事件类型
function GetEventType(parentId, eventLevel, parentPage, middleidentify) {
	$("#" + eventLevel).empty();
	// 获取事件类型
	$.ajax({
				url : window.rootPath + '/ui/eventReport/findEventTypeById/'
						+ parentId,
				dataType : 'json',
				type : 'get',
				success : function(result) {
					if (result.code == 1) {
						var isRegister = result.data.isRegister;
						var contenthtml = "";
						if (isRegister) {
							$("#registerDiv").show();
							$("#registerTable").hide();
							$("#registerD").show();
							
							$("#eventTypeSingleSelectDiv").hide();

							$("#roletitle").html("城管上报");
							var eventTypesHasChild = result.data.eventTypesHasChild;
							var eventTypesHasNoChild = result.data.eventTypesHasNoChild;

							if (eventTypesHasChild != undefined
									&& eventTypesHasChild.length > 0) {

								if ($(
										"#"
												+ eventTypesHasChild[0].eventLevel.extended1
												+ "_eventTypePanel").attr("id") == undefined) {
									$('body')
											.prepend(
													'<div data-role="page" id="'
															+ eventTypesHasChild[0].eventLevel.extended1
															+ '_eventTypePanel" style="background-color: #F5F5F5; background-size: cover">'
															+ '<div data-role="header" data-tap-toggle="true" data-theme="a">'
															+ '<span><a href="'+ parentPage+'" data-transition="slide" data-direction="reverse" class="pageBack" ><span class="fa fa-angle-left headleft"></span> </a></span>'
															+ '<h1>事件类型</h1>'
//															+ '<a href="'
//															+ parentPage
//															+ '" data-transition="slide" data-direction="reverse" class="ui-btn ui-btn-a ui-icon-back ui-btn-icon-notext ui-corner-all ui-shadow ui-btn-left">返回面板</a>'
															+ '</div>'
															+ '<div data-role="content">'
															/*
															 * + '<div
															 * data-role="collapsible"
															 * data-collapsed="false"
															 * data-collapsed-icon="carat-d"
															 * data-expanded-icon="carat-u"
															 * data-inset="false">' + '<h3>选择事件类型</h3>'
															 */
															+ '<ul data-role="listview" id="'
															+ eventTypesHasChild[0].eventLevel.extended1
															+ '_middleeventTypes"></ul>'
															+ '</div></div>');
								}
							}
							for (var i = 0; i < eventTypesHasChild.length; i++) {
								contenthtml = '<li id="'
										+ eventTypesHasChild[i].id
										+ '_li">'
										+ '<a id="'
										+ eventTypesHasChild[i].id
										+ '" userdefineid="'
										+ eventTypesHasChild[i].eventLevel.extended1
										+ '" href="#'
										+ eventTypesHasChild[i].eventLevel.extended1
										+ '_eventTypePanel" data-transition="slide" class="eventTypeclick">'
										+ '<h2 id="'
										+ eventTypesHasChild[i].id
										+ '_middleidentify">'
										+ eventTypesHasChild[i].eventName
										+ '</h2>'
//										+ '<h3 id="'
//										+ eventTypesHasChild[i].id
//										+ '_middleidentify">'
//										+ middleidentify
//										+ eventTypesHasChild[i].eventIdentify
//										+ '</h3>'
//										+ '<div style="overflow: auto;padding-top:0;margin-left:20px;">'
//										+ '<div class="div-inline"><p style="margin:0;">接收时限:'
//										+ eventTypesHasChild[i].acceptLimit
//										+ '小时</p></div>'
//										+ '<div class="div-inline"><p style="margin:0;">处理时限:'
//										+ eventTypesHasChild[i].processLimit
//										+ '小时</p></div></div>' 
										+ '</a>'
										+ '</li>';
								$("#" + eventLevel).append(contenthtml);
							}

							for (var i = 0; i < eventTypesHasNoChild.length; i++) {
								contenthtml = '<li id="'
										+ eventTypesHasNoChild[i].id
										+ '_li">'
										+ '<a id="'
										+ eventTypesHasNoChild[i].id
										+ '" href="#eventRegisterPanel" identifyEventTypeId="'
										+ eventTypesHasNoChild[i].id
										+ '" data-transition="slide" class="eventRegisterclick">'
										+ '<h2 id="'
										+ eventTypesHasNoChild[i].id
										+ '_eventTypeName">'
										+ eventTypesHasNoChild[i].eventName
										+ '</h2>'
//										+ '<h3 id="'
//										+ eventTypesHasNoChild[i].id
//										+ '_middleidentify">'
//										+ middleidentify
//										+ eventTypesHasNoChild[i].eventIdentify
//										+ '</h3>'
//										+ '<div style="overflow: auto;padding-top:0;margin-left:20px;">'
										+ '<div style="display:none"><p id="'
										+ eventTypesHasNoChild[i].id
										+ '_acceptLimitSpan" style="margin:0;">接收时限:'
										+ eventTypesHasNoChild[i].acceptLimit
										+ '小时</p></div>'
										+ '<div style="display:none"><p id="'
										+ eventTypesHasNoChild[i].id
										+ '_dealLimitSpan" style="margin:0;">处理时限:'
										+ eventTypesHasNoChild[i].processLimit
										+ '小时</p></div>'
//										</div>' 
										+ '</a>'
										+ '</li>';
								$("#" + eventLevel).append(contenthtml);
								$("#mainContent").append(
										'<input type="file" class="fileClick" id="file_'
												+ eventTypesHasNoChild[i].id
												+ '" name="'
												+ eventTypesHasNoChild[i].id
												+ '" style="display: none;"/>');
							}

							
							$('#' + eventLevel).listview('refresh');
							for (var i = 0; i < eventTypesHasChild.length; i++) {
								$("#"+eventTypesHasChild[i].id).removeClass("ui-btn-icon-right");
							}
							for (var i = 0; i < eventTypesHasNoChild.length; i++) {
								$("#"+eventTypesHasNoChild[i].id).removeClass("ui-btn-icon-right");
							}
						} else {
							$("#registerDiv").hide();
							$("#registerD").hide();
							$("#registerTable").show();
							$("#eventTypeSingleSelectDiv").show();
							$("#roletitle").html("事件上报");
						}
					} else {

					}
				}
			});
}
function currentLocation(location) {
	// alert(location.coords.longitude+":"+location.coords.latitude);
	$("#lng").val(location.coords.longitude);
	$("#lat").val(location.coords.latitude);
	getAdress(location.coords.longitude, location.coords.latitude);
}
function getAdress(longitude, latitude) {
	var markerPoint = new BMap.Point(longitude, latitude);
	BMap.Convertor.translate(markerPoint, 0, function initMap(point) {
		// 逆地址解析
		var geoc = new BMap.Geocoder();
		geoc.getLocation(point, function(rs) {
			var addComp = rs.addressComponents;
			jQuery("#locationDes").html(
					addComp.province + ", " + addComp.city + ", "
							+ addComp.district + ", " + addComp.street + ", "
							+ addComp.streetNumber);
		});
	}); // 转换坐标
}
function locationError(error) {
	// error occurred so stop watchPosition
	if (navigator.geolocation) {
		// navigator.geolocation.clearWatch(watchId);
	}
	switch (error.code) {
	case error.PERMISSION_DENIED:
		$("#locationDes").html("用户拒绝共享位置!");
		// alert("Location not provided");
		break;

	case error.POSITION_UNAVAILABLE:
		$("#locationDes").html("地址无效!");
		// alert("Current location not available");
		break;

	case error.TIMEOUT:
		$("#locationDes").html("获取位置超时!");
		// alert("Timeout");
		break;

	default:
		$("#locationDes").html("未知错误!");
		break;
	}
}
function GetLocationWithHTMLAPI() {
	$("#locationDes").html("正在获取位置......");
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(currentLocation,
				locationError, {
					// 指示浏览器获取高精度的位置，默认为false
					enableHighAccuracy : true,
					// 指定获取地理位置的超时时间，默认不限时，单位为毫秒
					timeout : 5000,
					// 最长有效期，在重复获取地理位置时，此参数指定多久再次获取位置。
					maximumAge : 3000
				});
		// watchId = navigator.geolocation.watchPosition(showLocation,
		// locationError);//实时定位的方法
	} else {
		$("#locationDes").html("浏览器不支持定位!");
		// alert("Browser doesn't support Geolocation. Visit http://caniuse.com
		// to see browser support for the Geolocation API.");
	}
};

function GetYourLocation() {
	$("#locationDes").html("正在获取位置......");
	// 创建百度地图控件
	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r) {
		if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			// 以指定的经度与纬度创建一个坐标点
			var pt = new BMap.Point(r.point.lng, r.point.lat);
			var cj02 = bd09togcj02(r.point.lng, r.point.lat);
			var gps = gcj02towgs84(cj02[0], cj02[1]);
			$("#lng").val(gps[0]);
			$("#lat").val(gps[1]);
			// 创建一个地理位置解析器

			var geoc = new BMap.Geocoder();
			geoc.getLocation(pt,
					function(rs) {// 解析格式：城市，区县，街道
						var addComp = rs.addressComponents;
					//	var s="<img alt='当前位置' src='/wcsi/img/yourlocation.png' width='4%' id='locationimg'/>";
						jQuery("#locationDes").html(
								addComp.province + ", " + addComp.city + ", "
										+ addComp.district + ", " + addComp.street + ", "
										+ addComp.streetNumber);
					});
			GetGridGrading($("#lng").val(), $("#lat").val());
			
			var data = {
				"longitude" : $("#lng").val(),
				"latitude" : $("#lat").val(),
				"id" : "exdePoint"
			}
			createFlickerPoint(data, 'html');
			setTimeout(function() {
				setCenter();
			}, 500);
			
		} else {
			$("#locationDes").html('定位失败');
		}
	}, {
		enableHighAccuracy : true
	})// 指示浏览器获取高精度的位置，默认false
};
// 获取grading
function GetGridGrading(longitude, latitude) {
	$.ajax({
		url : rootPath + "/ui/eventRegister/getGrading?" + "&longitude="
				+ longitude + "&latitude=" + latitude,
		dataType : 'json',
		type : 'get',
		contentType : "application/json",
		success : function(result) {
			if (result.data.codeForGrid <= 0) {

			} else {
				initGradingLevel(result.data.gradings);
			}
		}
	});
};
// 重新加载扣分层级选项
function initGradingLevel(gradings) {

	$("#registerEventEvaluateLevel").empty();
	if (gradings) {
		for (var i = 0; i < gradings.length; i++) {
			jQuery("#registerEventEvaluateLevel").append(
					"<option value='" + gradings[i].id + "'>"
							+ gradings[i].gradingName + "</option>");
		}
	}
};
// 点击提交按钮时
$("#saveOrUpdateBtn").click(
	function() {
		if(_phoneType=="Android"){
			window.jump.proShow(); 
		}else if(_phoneType=="Ios"){
			window.webkit.messageHandlers.submitWaiting.postMessage({body: 'open'});
		}else{
			$("#popupView").popup("open");
		}
		jQuery("#saveOrUpdateBtn").prop("disabled", true);

		var lng = 0;
		if($("#lng2").val() != undefined && $("#lng2").val() != ""){
			lng = $("#lng2").val();
		}else if ($("#lng").val() != undefined && $("#lng").val() != "") {
			lng = $("#lng").val();
		}
		
		var lat = 0;
		if($("#lat2").val() != undefined && $("#lat2").val() != ""){
			lat = $("#lat2").val();
		}else if ($("#lat").val() != undefined && $("#lat").val() != "") {
			lat = $("#lat").val();
		}
		

		var eventRegister = new Array();
		for (var i = 0; i < oldlist.length; i++) {
			var o = {
				"registerEventType" : {
					"id" : oldlist[i].id
				},
				"registerEventImgAdress":$("#"+oldlist[i].id+"_avatartD").attr("src"),
				"registerEventName" : oldlist[i].registerEventName,
				"registerEventIdentify" : oldlist[i].registerEventIdentify,
				"registerEventMemo" : oldlist[i].registerEventMemo,
				"registerEventContent" : oldlist[i].registerEventContent,
				"acceptLimitSpan" : oldlist[i].acceptLimitSpan,
				"dealLimitSpan" : oldlist[i].dealLimitSpan,
				"registerEventAdress" : oldlist[i].registerEventAdress,
				"longitude" : lng,
				"latitude" : lat
			};

			if (oldlist[i].registerEventEvaluateLevel != undefined
					&& oldlist[i].registerEventEvaluateLevel != "") {
				o.registerEventEvaluateLevel = {
					"id" : oldlist[i].registerEventEvaluateLevel
				}
			}

			if (oldlist[i].registerEventSeriousLevel != undefined
					&& oldlist[i].registerEventSeriousLevel != "") {
				o.registerEventSeriousLevel = {
					"id" : oldlist[i].registerEventSeriousLevel
				}
			}

			if (oldlist[i].registerEventToPartBaseInfo != undefined
					&& oldlist[i].registerEventToPartBaseInfo != "") {
				o.registerEventToPartBaseInfo = {
					"id" : oldlist[i].registerEventToPartBaseInfo
				}
			}
			eventRegister.push(o);
		}

		var data = {};

		var eventImg=$("#avatart").attr("src");
		var eventReport = {
			"reportImgAdress":eventImg,
			"longitude" : lng,
			"latitude" : lat,
			"reportEventType" : {
				"id" : $("#eventTypeSingleSelect").val()
			},
			"reportContent" : $("#reportContent").val(),
			"reportMemo" : $("#reportMemo").val(),
			"reportAdress" : $("#locationDes2").html()==''?$("#locationDes").html():$("#locationDes2").html()
		};
		
		
		if($("#eventTypeSingleSelectDiv").is(":hidden")){
			if(oldlist.length == 0){
				alert('请选择至少一个小类事件上报！');
				if(_phoneType=="Android"){
					window.jump.proDismiss(); 
				}else if(_phoneType=="Ios"){
					window.webkit.messageHandlers.submitWaiting.postMessage({body: 'close'});
				}else{
					$("#popupView").popup("close");
				}
				jQuery("#saveOrUpdateBtn").prop("disabled", false);
				return;
			}else{
				eventReport.reportEventType =  {
						"id" :  oldlist[0].id
					}
			}
		}
		

		var fileIds = new Array();
		var fileNames = "";
		var formHandle = document.getElementById("pageone");
		var tagElements = formHandle.getElementsByTagName('input');
		for (var j = 0; j < tagElements.length; j++) {
			element = tagElements[j];
			if ("file" == element.type) {
				fileIds.push(element.id);
				fileNames += element.name + ";";
			}
		}
		data = {
			"identify" : $("#identify").val(),
			"eventReport" : JSON.stringify(eventReport),
			"eventRegister" : JSON.stringify(eventRegister),
			"fileNames" : fileNames
		};
		//解决IOS上传bug,重新使用上传方法
		$.ajax({
    		url : window.rootPath + "/ui/eventReport/saveReportAndRegisterEventWithoutInputFile",
    		dataType : 'json',
    		type : 'post',
    		data : data,
    		success : function(result) {
    			if(_phoneType=="Android"){
					window.jump.proDismiss(); 
				}else if(_phoneType=="Ios"){
					window.webkit.messageHandlers.submitWaiting.postMessage({body: 'close'});
				}else{
					$("#popupView").popup("close");
				}
				if (result.code == "1") {
					alert("上报成功!");
					window.location.href = window.rootPath
							+ "/ui/mobileMain?device=mobile&identify="
							+ $("#identify").val();
				}else{
					alert("上报失败!");
				}
				jQuery("#saveOrUpdateBtn").prop("disabled", false);
    		}
    	});
		return;
		$.ajaxFileUpload({
			url : window.rootPath
					+ "/ui/eventReport/saveReportAndRegisterEvent",
			secureuri : false,// 是否需要安全协议
			fileElementId : fileIds,// 文件上传的Id属性
			dataType : 'text',
			data : data,
			success : function(result, status) {	
				if(_phoneType=="Android"){
					window.jump.proDismiss(); 
				}else if(_phoneType=="Ios"){
					window.webkit.messageHandlers.submitWaiting.postMessage({body: 'close'});
				}else{
					$("#popupView").popup("close");
				}
				if (status == "success") {
					alert("上报成功!");
					window.location.href = window.rootPath
							+ "/ui/mobileMain?device=mobile&identify="
							+ $("#identify").val();
				}else{
					alert("上报失败!");
				}
				jQuery("#saveOrUpdateBtn").prop("disabled", false);
				
			}
		});

		// 设置不提交
		return false;
	});